﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;
using System.Security.Principal;
using SalePoints.Models;
using SystemX.Infrastructure;
using SystemX.Utility;


namespace SalePoints.Web.Webservices
{
	[ServiceContract(Namespace = "http://wcf.m18.com")]
	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
	public class SalePointServices
	{
		/// <summary>
		/// Check NT Logon
		/// </summary>
		/// <returns></returns>
		[OperationContract]
		public UserIdentity NTLogon()
		{
			var WinIdentity =OperationContext.Current.ServiceSecurityContext.WindowsIdentity;
			
			return new UserIdentity {
				AuthenticationType = WinIdentity.AuthenticationType,
				IsAuthenticated=WinIdentity.IsAuthenticated,
				Name=WinIdentity.Name
			};
			
		}
		[OperationContract]
		public List<SalePointInfo> LoadData(DataLegendGroup group, SaleChannel channel) {
			var msg = new BOMessager();
			var items = BOSalePoint.LoadData(group, channel, out msg);
			return items;
		}
		[OperationContract]
		public void Log(BOMessager msg) {
			Logger<SalePointServices>.Current.Info(msg.Body);
		}
		/// <summary>
		/// 按时统计昨天、上周同期的数据。并保存于xml文件中(app_data/cache/SalePoints.Hourly.xml),同时至于缓存中
		/// </summary>
		[OperationContract]
		public void StatHourly(DateTime statDateFlag,out BOMessager msg) {
			msg = new BOMessager();
			BOSalePoint.StatHourly(statDateFlag, out msg);
		}
	}
}
